﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Reflection;

namespace QLTV.Forms.BaoMat
{
    public partial class frmLogin : BaseForm
    {   
        public ResourceManager rm;
        public frmLogin()
        {
            InitializeComponent();
            myCultureInfo = new CultureInfo(comboBoxEdit1.EditValue.ToString());
            Thread.CurrentThread.CurrentUICulture = myCultureInfo;
            rm = new ResourceManager("QLTV.Properties.Resources", Assembly.GetExecutingAssembly());

        }
     
        public Boolean LogonSuccessful { get; set; }


        private void simpleButton2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void cmdLogin_Click(object sender, EventArgs e)
        {
            try
            {
                tblUsersTableAdapter1.login(dsUsers1.tblUsers, txtUserName.Text, txtPassword.Text);


                if (dsUsers1.tblUsers.Rows.Count > 0)
                {

                    this.LogonSuccessful = true;
                    Program.username = txtUserName.Text;
                    QLTV.Database.dsUsersTableAdapters.tblNhanSuTableAdapter tadNhanSu = new Database.dsUsersTableAdapters.tblNhanSuTableAdapter();
                    Program.EmployeeName = tadNhanSu.selectTenNhanSu((int)tblUsersTableAdapter1.selectIdNhanSu(Program.username)).ToString();

                    if (comboBoxEdit1.SelectedIndex == 0)
                    {
                        Program.language = "vi-VN";
                    }
                    else
                        Program.language = "en";
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(rm.GetString("sLoginError", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OK);
                    this.LogonSuccessful = false;
                }
            }
            catch (SqlException ex) {
                throw new Exception(ex.ToString());
             
            }
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxEdit1.SelectedIndex == 0)
            {
                this.Text = "Hệ Thống Quản Lý Thuyền Viên";
                lblPass.Text = "Mật khẩu";
                lblUser.Text = "Tài khoản";
                title.Text = "Hệ Thống Quản Lý Thuyền Viên";
                cmdExit.Text = "Thoát";
                cmdLogin.Text = "Đăng nhập";

            }
            else {
                this.Text = "Crew Schedule Management System";
                lblPass.Text = "Password";
                lblUser.Text = "Username";
                title.Text = "Crew Schedule Management System";
                cmdExit.Text = "Exit";
                cmdLogin.Text = "Login";
            }
              
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            this.Text = "Hệ Thống Quản Lý Thuyền Viên";
            lblPass.Text = "Mật khẩu";
            lblUser.Text = "Tài khoản";
            title.Text = "Hệ Thống Quản Lý Thuyền Viên";
            cmdExit.Text = "Thoát";
            cmdLogin.Text = "Đăng nhập";

        }

        private void frmLogin_Shown(object sender, EventArgs e)
        {

            lblUser.Control.Focus();

        }

    }
}